﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rosetta.Composition;
using Rosetta.Default;

namespace Rosetta.Tests
{
    [TestClass]
    public class NodeTests
    {
        #region Public Methods

        [TestMethod]
        public void TestNodeConnection()
        {
            var container = new Container();
            var template = new Template(container);
            var inputNode = template.AddInputNode("Rosetta.Tests.NodeTests+NullInputter, Rosetta.Tests", "GetInt32");
            var typeConverterNode = inputNode.AddChild("Rosetta.Default.AddIns.TypeConverter, Rosetta.Default", "Int32ToString", 0).EndPoint;
            typeConverterNode.AddChild("Rosetta.Tests.Mocks.DynamicTextWriterOutput, Rosetta.Tests", "WriteLine", 1);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestNullAddIn()
        {
            var container = new Container();
            container.GetAddIn("None");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestInvalidTypes()
        {
            var container = new Container();
            var template = new Template(container);
            var inputNode = template.AddInputNode("Rosetta.Tests.NodeTests+NullInputter, Rosetta.Tests", "GetInt32");
            var converterNode = inputNode.AddChild("Rosetta.Default.AddIns.TypeConverter, Rosetta.Default", "StringToInt32", 0).EndPoint;

            Assert.AreEqual(0, converterNode.MissingArguments.Length);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestInvalidMethodName()
        {
            var container = new Container();
            var template = new Template(container);
            
            template.AddInputNode("Rosetta.Tests.NodeTests+NullInputter, Rosetta.Tests", "GetLolz");
        }

        #endregion

        #region Nested Types

        private sealed class NullInputter : Inputter
        {
            #region Constructors

            public NullInputter()
                : base("Null Inputter")
            {
                Add("GetInt32", () => 0);
                Add<string>("GetString", () => null);
            }

            #endregion
        }

        #endregion
    }
}